﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DTO;
using DAO;

namespace QLDaiLy.GUI.UserControl
{
    public partial class TimKiemNangCao : DevExpress.XtraEditors.XtraUserControl
    {
        public TimKiemNangCao()
        {
            InitializeComponent();
            fillYearCombobox();
        }
        private void LoadDanhSachQuan()
        {
            List<QuanDTO> list = new List<QuanDTO>();
            list = QuanDAO.LoadDanhSachQuan();
            foreach(var quan in list)
            {
                cbbQuan.Properties.Items.Add(quan.TenQuan);
            }
          
        }
        private void LoadDanhSachLoaiDaiLy()
        {
 
            List<LoaiDaiLyDTO> list = new List<LoaiDaiLyDTO>();
            list = LoaiDaiLyDAO.LoadDanhSachLoaiDaiLy();
            foreach (var loaidaily in list)
            {
                cbbLoaiDaiLy.Properties.Items.Add(loaidaily.TenLoaiDaiLy);
            }
       
        }
        private void TimKiemNangCao_Load(object sender, EventArgs e)
        {
            LoadDanhSachQuan();
            LoadDanhSachLoaiDaiLy();
            fillMonthCombobox();
         
        }
        public void fillYearCombobox()
        {
            int year = DateTime.Now.Year;
            for (int i = 2005; i <= year; i++)
            {
                cbbNamTiepNhanTu.Properties.Items.Add(i);
                cbbNamTiepNhanDen.Properties.Items.Add(i);
            }
            cbbNamTiepNhanTu.SelectedIndex =-1;
            cbbNamTiepNhanDen.SelectedIndex = -1;
            cbbNamTiepNhanTu.Properties.Sorted = true;
        }
        public void fillMonthCombobox()
        {
           // int year = DateTime.Now.Year;
            for (int i = 1; i <= 12; i++)
            {
                cbbThangTu.Properties.Items.Add(i);
                cbbThangDen.Properties.Items.Add(i);
            }
            cbbThangTu.SelectedIndex = -1;
            cbbThangDen.SelectedIndex = -1;
            cbbNamTiepNhanTu.Properties.Sorted = true;
        }
        private void cbbNamTiepNhanTu_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }
        private void btnTim_Click(object sender, EventArgs e)
        {
          
            int namTu, namDen, thangTu, thangDen, noTu, noDen;
            namTu=namDen=thangTu=thangDen=noTu=noDen= 1000;
            DaiLyDTO dl = new DaiLyDTO();
            dl.TenDaiLy = textbTenDaiLy.Text;
            dl.DiaChi = textbDiaChi.Text;

            if (cbbNamTiepNhanTu.SelectedIndex != -1)
            {
                namTu = cbbNamTiepNhanTu.SelectedItem.GetHashCode();
            }
            if (cbbNamTiepNhanDen.SelectedIndex != -1)
            {
                namDen = cbbNamTiepNhanDen.SelectedItem.GetHashCode();
            }
            if (cbbThangTu.SelectedIndex != -1)
            {
                thangTu = cbbThangTu.SelectedItem.GetHashCode();
               // thangTu =int.Parse(cbbThangTu.Text.ToString());
            }
            if (cbbThangDen.SelectedIndex != -1)
            {
                thangDen = Convert.ToInt32(cbbThangDen.SelectedItem.GetHashCode());
            }
            if (cbbNoDaiLyTu.SelectedIndex != -1)
            {
                namTu = cbbNoDaiLyTu.SelectedItem.GetHashCode();
            }
            if (cbbNoDaiLyDen.SelectedIndex != -1)
            {
                noDen = cbbNoDaiLyDen.SelectedItem.GetHashCode();
            }
            DataTable dt = DaiLyDAO.TimKiemNangCao(dl, namTu, namDen, thangTu, thangDen, noTu, noDen);
            DatadridView.DataSource = dt;

     
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {

        }

        private void btnPhieuThu_Click(object sender, EventArgs e)
        {
            TableLayoutPanel tb = (TableLayoutPanel)this.Parent;
            tb.Controls.Remove(tb.GetControlFromPosition(0,1));
            PhieuThuTien frm = new PhieuThuTien();
            tb.Controls.Add(frm, 0, 1);

            
        }
    }
}
